import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import *


class QSliderDemo(QWidget):
    def __init__(self):
        super(QSliderDemo, self).__init__()
        self.iniUI()

    def iniUI(self):
        self.setWindowTitle("滑块控件演示")
        self.resize(400, 700)

        self.layout = QVBoxLayout()
        self.label = QLabel('你好PyQt5')
        self.label.setStyleSheet("color:blue")
        self.label.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(self.label)

        self.qSlider1 = QSlider(Qt.Horizontal)
        # 设置最小值
        self.qSlider1.setMinimum(12)
        # 设置最大值
        self.qSlider1.setMaximum(48)
        # 设置步长
        self.qSlider1.setSingleStep(1)
        #  设置当前值
        self.qSlider1.setValue(18)
        #  设置刻度在下方
        self.qSlider1.setTickPosition(QSlider.TicksBelow)
        #  设置刻度的间隔
        self.qSlider1.setTickInterval(2)
        #  绑定槽
        self.qSlider1.valueChanged.connect(self.valueChange)
        #  添加到布局控件
        self.layout.addWidget(self.qSlider1)

        self.qSlider2 = QSlider(Qt.Vertical)
        # 设置最小值
        self.qSlider2.setMinimum(1)
        # 设置最大值
        self.qSlider2.setMaximum(60)
        # 设置步长
        self.qSlider2.setSingleStep(1)
        #  设置当前值
        self.qSlider2.setValue(30)
        #  设置刻度在左侧
        self.qSlider2.setTickPosition(QSlider.TicksLeft)
        #  设置刻度线之间的间隔
        self.qSlider2.setTickInterval(2)
        self.qSlider2.valueChanged.connect(self.valueChange)
        self.layout.addWidget(self.qSlider2)

        self.setLayout(self.layout)


    def valueChange(self):
        print('当前值：%s' % self.sender().value())
        size = self.sender().value()
        self.label.setFont(QFont('Microsoft YaHei',size))



if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QSliderDemo()
    main.show()
    sys.exit(app.exec_())
